package com.shiguiwu.springmybatis.designpattern.strategy.event;

import com.shiguiwu.springmybatis.designpattern.strategy.ICouponDiscount;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

/**
 * @description: 折扣就优惠
 * @author: stone
 * @date: Created by 2021/9/9 17:12
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.strategy.event
 */
@Slf4j
public class ZKCouponDiscount implements ICouponDiscount<Double> {

    /**
     *
     * @param couponInfo 券折扣信息；直减、满减、折扣、N元购
     * @param price sku⾦金金额
     * @return 价格
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal price) {
        BigDecimal bigDecimal = price.multiply(new BigDecimal(couponInfo)).setScale(2, BigDecimal.ROUND_HALF_UP);
        if (bigDecimal.compareTo(BigDecimal.ZERO) < 1) {
            return BigDecimal.ONE;
        }
        log.info("折扣优惠：折扣 {}，原来价格是 {}，最终价格是{}",  couponInfo,price, bigDecimal);
        return bigDecimal;
    }

}
